<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>API测试页面</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
        }
        button {
            padding: 10px;
            margin: 10px 0;
            cursor: pointer;
        }
        pre {
            background: #f5f5f5;
            padding: 10px;
            border-radius: 5px;
            overflow: auto;
        }
    </style>
</head>
<body>
    <h1>API测试页面</h1>
    
    <div>
        <h2>测试后端API</h2>
        <button onclick="testDirectAPI()">直接测试后端API</button>
        <pre id="direct-result">结果将显示在这里...</pre>
    </div>
    
    <div>
        <h2>测试前端代理API</h2>
        <button onclick="testProxyAPI()">测试前端代理API</button>
        <pre id="proxy-result">结果将显示在这里...</pre>
    </div>

    <script>
        async function testDirectAPI() {
            const resultElem = document.getElementById('direct-result');
            resultElem.textContent = "请求中...";
            
            try {
                const response = await fetch('http://localhost:8000/chat/history?user_id=5');
                const data = await response.json();
                resultElem.textContent = JSON.stringify(data, null, 2);
            } catch (error) {
                resultElem.textContent = `错误: ${error.message}`;
            }
        }
        
        async function testProxyAPI() {
            const resultElem = document.getElementById('proxy-result');
            resultElem.textContent = "请求中...";
            
            try {
                const response = await fetch('/chat/history?user_id=5');
                const data = await response.json();
                resultElem.textContent = JSON.stringify(data, null, 2);
            } catch (error) {
                resultElem.textContent = `错误: ${error.message}`;
            }
        }
    </script>
</body>
</html> 